package game.handler;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;

import game.kcp.KcpOnUdp;
import game.scene.SceneConst;
import game.scene.SceneManager;
import game.scene.msg.SMessage;
import game.scene.msg.info.SceneObjInfo;
import game.scene.msg.req.ReqEnterSceneMsg;
import game.scene.msg.res.ResSceneObjShowMsg;
import game.scene.obj.Player;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author WinkeyZhao
 * @note
 */
public class ReqEnterSceneHandler implements IMessageHandler {

    @Override
    public void handMsg(ChannelHandlerContext ctx, byte[] data) {
        Player player = ctx.channel().attr(SceneConst.attrPlayer).get();
        String content;
        try {
            content = new String(data, "UTF-8");
            ReqEnterSceneMsg msg = JSON.parseObject(content, ReqEnterSceneMsg.class);
            SceneManager.getIns().enterScene(player, 75, 75);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void handKcpMsg(KcpOnUdp kcp, byte[] data) {
        Player player = (Player) kcp.getSessionValue(SceneConst.attrPlayer);
        String content;
        try {
            content = new String(data, "UTF-8");
            ReqEnterSceneMsg msg = JSON.parseObject(content, ReqEnterSceneMsg.class);
            SceneManager.getIns().enterScene(player, 75, 75);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
